package cn.itsource.Controller.html;

import cn.itsource.Utils.JSONResult;
import cn.itsource.domain.BlogArticle;
import cn.itsource.query.BaseQuery;
import cn.itsource.service.IBlogArticleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/html/blogArticle")
public class HtmlBlogArticleController {

    /**
     * 注入业务层依赖
     */
    @Autowired
    private IBlogArticleService blogArticleService;


    /**
     * 分页查询所有的文章信息
     * @return
     */
    @RequestMapping(value = "/pageBlogList",method = RequestMethod.POST)
    public JSONResult getAllArticle(@RequestBody BaseQuery query){
        // 获取所有的文章分页数据
        PageInfo<BlogArticle> pageInfo = blogArticleService.getAllArticleByPage(query);
        return JSONResult.createSuccess(pageInfo);
    }

    /**
     * 根据前端传过来的id查询对应的文章数据
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JSONResult getAllArticle(@PathVariable("id") Long id){
        // 调用业务层根据id获取文章详情数据
        BlogArticle article = blogArticleService.getbolgByid(id);
        return JSONResult.createSuccess(article);
    }
}
